#include <linux/module.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/types.h>


#define CHRDEVBASE_MAJOR 200
uint8_t kernel_buff[1024] = {0};

static int hello_world_open(struct inode * inode, struct file * file)
{
    printk("hello_world_open \r\n");
    return 0;
}

static int hello_world_release (struct inode * inode, struct file * file)
{
    printk("hello_world_release \r\n");
    return 0;
}

static ssize_t hello_world_read(struct file *file, char __user *buffer, size_t size, loff_t * ppos)
{
    printk("hello_world_read size:%ld\r\n",size);
    copy_to_user(buffer,kernel_buff,size);
    return size;
}

static ssize_t hello_world_write(struct file *file, const char __user *buffer, size_t size, loff_t * ppos)
{
    printk("hello_world_write size:%ld\r\n",size);
    copy_from_user(kernel_buff,buffer,size);
    return size;
}

static const struct file_operations hello_world_fops = {
    .owner      = THIS_MODULE,
    .open       = hello_world_open,
    .release    = hello_world_release,
    .read       = hello_world_read,
    .write      = hello_world_write,
};


static int __init hello_driver_init(void) 
{
    int ret;
    printk("hello_driver_init \r\n");
    ret = register_chrdev(CHRDEVBASE_MAJOR,"hello_driver", &hello_world_fops);
    return 0;
}


static void __exit hello_driver_cleanup(void)
{
    unregister_chrdev(CHRDEVBASE_MAJOR,"hello_driver");
    printk("hello_driver_cleanup\r\n");
}


module_init(hello_driver_init);
module_exit(hello_driver_cleanup);

MODULE_LICENSE("GPL");




